//
//  SecondTableViewCell.m
//  iNews
//
//  Created by lanou3g on 14-12-8.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "SecondTableViewCell.h"
#import "HomeModel.h"
#import "UIImage+ImageDown.h"
#import "AdaptHeigth.h"

@implementation SecondTableViewCell

- (void)dealloc
{
    [_imv release];
    [_titleLabel release];
    [_litterLabel release];
    [_numberLabel release];
    
    [super dealloc];
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self addAllViews];
        
    }
    return self;
}

- (void)addAllViews
{
    
    //图
    self.imv = [[[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 90, 80)] autorelease];
    self.imv.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.imv];
    
    //大标题
    self.titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imv.frame) + 5, CGRectGetMinY(self.imv.frame), [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetWidth(self.imv.frame), 20)] autorelease];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
  // self.titleLabel.backgroundColor = [UIColor yellowColor];
   // self.titleLabel.numberOfLines = 0;
    [self.contentView addSubview:self.titleLabel];

    //小标题

    self.litterLabel = [[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.imv.frame) + 5, CGRectGetMaxY(self.titleLabel.frame)+5, CGRectGetWidth(self.titleLabel.frame), CGRectGetHeight(self.imv.frame) - CGRectGetHeight(self.titleLabel.frame)-20)] autorelease] ;
    self.litterLabel.font = [UIFont systemFontOfSize:12];
    self.litterLabel.numberOfLines = 0;
    [self.contentView addSubview:self.litterLabel];
    
    //关注人数
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.litterLabel.frame), CGRectGetMaxY(self.litterLabel.frame), CGRectGetWidth(self.litterLabel.frame) - 150, 20)] autorelease];
    label.font = [UIFont systemFontOfSize:12];
    label.text = @"关注人数:";
    [self addSubview:label];
    
    self.numberLabel = [[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label.frame), CGRectGetMaxY(self.litterLabel.frame), 150, 20)] autorelease];
    self.numberLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.numberLabel];
}

- (void)writeMessage:(HomeModel *)homeM
{
//    CGRect rect = self.litterLabel.frame;
//    rect.size.height = [AdaptHeigth heigthOfString:homeM.title];
//    NSLog(@"%f",rect.size.height);
//    self.litterLabel.frame = rect;
    
    self.titleLabel.text = homeM.title;
    self.litterLabel.text = homeM.digest;
    self.numberLabel.text = [NSString stringWithFormat:@"%@",homeM.replyCount];
    
    self.imv.image = [UIImage imageWithUrlString:homeM.imgsrc myBlock:^(UIImage *image) {
        
        self.imv.image = image;
      //  NSLog(@"%f,%f",image.size.width,image.size.height);
    }];
    
}




- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
